//
//  CZStatusBottomView.swift
//  GZWeibo666
//
//  Created by Apple on 15/11/28.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

/*
enum CZNetworkToolError: Int {
case EmptyAccessToken = -1
case EmptyUid = -2
*/

enum CZStatusButtonViewType: NSInteger
{
    case forwardBtnType = 2
    case commentBtnType = 3
}

class CZStatusBottomView: UIView {

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        prepareUI()
    }

    // MARK: - 准备UI
    private func prepareUI() {
        backgroundColor = UIColor(white: 0.98, alpha: 1)
        
        // 添加子控件
        addSubview(forwardButton)
        addSubview(commentButton)
        addSubview(likeButton)
        addSubview(sImageViewFirst)
        addSubview(sImageViewSecond)
        
        // 添加约束
        /// 平铺子控件
        /// self: 父控件
        /// views: 哪些子控件要平铺
        /// insets边距
        self.ff_HorizontalTile([forwardButton, commentButton, likeButton], insets: UIEdgeInsetsZero)
        
        sImageViewFirst.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: forwardButton, size: nil)
        
        sImageViewSecond.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: commentButton, size: nil)
    }
    
    ///将按钮的私有性删除
    
    // MARK: - 懒加载
    /// 转发按钮
    lazy var forwardButton: UIButton =
    {
        let forwardBtn = UIButton(imageName: "timeline_icon_retweet", title: "转发")
        
        forwardBtn.addTarget(self, action: "forwardBtnClick:", forControlEvents: UIControlEvents.TouchUpInside)
        
        return forwardBtn
    }()
    
    
    //转发按钮的点击方法
    func forwardBtnClick(forwardBtn: UIButton)
    {
        print("你点击了转发按钮");
        forwardBtn.tag =  CZStatusButtonViewType.forwardBtnType.rawValue
        self.delegate?.CZStatusBottomViewModal(self, clickBtn: forwardButton)
    }

    /// 评论按钮
    lazy var commentButton: UIButton =
    {
        let commentBtn = UIButton(imageName: "timeline_icon_comment", title: "评论")
        
        commentBtn.addTarget(self, action: "commentBtnClick:", forControlEvents: UIControlEvents.TouchUpInside)
        
        return commentBtn
    }()
    
    //点击了评论按钮
    func commentBtnClick(commentBtn: UIButton)
    {
        print("点击了评论按钮");
        commentBtn.tag = CZStatusButtonViewType.commentBtnType.rawValue
        self.delegate?.CZStatusBottomViewModal(self, clickBtn: commentButton)
    }
    
    
    /// 赞按钮
    lazy var likeButton: UIButton = UIButton(imageName: "timeline_icon_unlike", title: "赞")

    
    /// 分割线1
    private lazy var sImageViewFirst: UIImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line_highlighted"))
    
    /// 分割线2
    private lazy var sImageViewSecond: UIImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line_highlighted"))
    
    
    //bottom代理
    var delegate: CZStatusBottomViewDelegate?
}




//设置代理
protocol CZStatusBottomViewDelegate
{
    //代理方法
    func CZStatusBottomViewModal(bottomView: CZStatusBottomView, clickBtn: UIButton)
}


